package com.linkhub.oms.data.sync.api.wms.domain.request;

import com.alibaba.fastjson.annotation.JSONField;
import com.linkhub.oms.common.util.QtBeanUtil;
import com.linkhub.oms.data.sync.api.wms.domain.dto.WmsSyncProductDTO;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;

import java.io.Serializable;

/**
 * @Description: SyncProductRequest
 * @Author: echo
 * @Date: 2024/5/5 21:19
 * @Version: 1.0
 */
@NoArgsConstructor
@Data
public class SyncProductRequest implements Serializable {


    /**
     * request
     */
    @JSONField(name = "request")
    private Request request;

    public static SyncProductRequest createRequest( Request.Item item,
                                                    Request.ExtendProps extendProps, String customerId, String warehouseCode, String supplierCode, String supplierName ) {
        SyncProductRequest request = new SyncProductRequest();
        Request innerRequest = new Request();
        innerRequest.setItem(item);
        innerRequest.setExtendProps(extendProps);
        innerRequest.setOwnerCode(customerId);
        innerRequest.setWarehouseCode(warehouseCode);
        innerRequest.setSupplierCode(supplierCode);
        innerRequest.setSupplierName(supplierName);
        request.setRequest(innerRequest);

        return request;
    }

    public static SyncProductRequest createSyncProductRequest( WmsSyncProductDTO wmsSyncProductDTO) {
        SyncProductRequest.Request.Item item = new SyncProductRequest.Request.Item();
        SyncProductRequest.Request request = new SyncProductRequest.Request();

        // 复制属性到嵌套的 item 对象
        QtBeanUtil.copyProperties(wmsSyncProductDTO, item);

        // 复制属性到 request 对象
        QtBeanUtil.copyProperties(wmsSyncProductDTO, request);

        // 设置嵌套对象
        request.setItem(item);

        // 创建 SyncProductRequest 并设置 request
        SyncProductRequest syncProductRequest = new SyncProductRequest();
        syncProductRequest.setRequest(request);

        return syncProductRequest;
    }

    /**
     * Request
     */
    @NoArgsConstructor
    @Data
    public static class Request {
        /**
         * actionType
         */
        @JSONField(name = "actionType")
        private String actionType = "add";

        /**
         * warehouseCode
         */
        @JSONField(name = "warehouseCode")
        private String warehouseCode;

        /**
         * ownerCode
         */
        @JSONField(name = "ownerCode")
        private String ownerCode;

        /**
         * supplierCode
         */
        @JSONField(name = "supplierCode")
        private String supplierCode;

        /**
         * supplierName
         */
        @JSONField(name = "supplierName")
        private String supplierName;

        /**
         * item
         */
        @JSONField(name = "item")
        private Item item;

        /**
         * extendProps
         */
        @JSONField(name = "extendProps")
        private ExtendProps extendProps;

        @NoArgsConstructor
        @Data
        public static class Item {
            /**
             * 必填，货品编码，多货主模式下为货主代码+商品条码,直接传商品ID（需确保全局唯一）
             */
            @JSONField(name = "itemCode")
            private String itemCode;

            /**
             * 条件必填, 条件为商品同步接口更新时,入参itemId不为空，此值不为空是否为更新货品信息？（先不填）
             */
            @JSONField(name = "itemId")
            private String itemId;

            /**
             * 必填，货品名称（自定义）
             */
            @JSONField(name = "itemName")
            private String itemName;

            /**
             * 商品简称
             */
            @JSONField(name = "shortName")
            private String shortName;

            /**
             * 商品英文名称
             */
            @JSONField(name = "englishName")
            private String englishName;

            /**
             * 是否有效
             */
            @JSONField(name = "isValid")
            private String isValid;

            /**
             * 必填，用分号隔开，系统生成条码放在第一位
             */
            @JSONField(name = "barCode")
            private String barCode;

            /**
             * 商品标题
             */
            @JSONField(name = "title")
            private String title;

            /**
             * 品牌代码
             */
            @JSONField(name = "brandCode")
            private String brandCode;

            /**
             * 品牌名称
             */
            @JSONField(name = "brandName")
            private String brandName;

            /**
             * 商品属性，物流属性
             */
            @JSONField(name = "skuProperty")
            private String skuProperty;

            /**
             * 长
             */
            @JSONField(name = "length")
            private String length;

            /**
             * 宽
             */
            @JSONField(name = "width")
            private String width;

            /**
             * 高
             */
            @JSONField(name = "height")
            private String height;

            /**
             * 体积
             */
            @JSONField(name = "volume")
            private String volume;

            /**
             * 毛重
             */
            @JSONField(name = "grossWeight")
            private String grossWeight;

            /**
             * 净重
             */
            @JSONField(name = "netWeight")
            private String netWeight;

            /**
             * 货号
             */
            @JSONField(name = "goodsCode")
            private String goodsCode;

            /**
             * 颜色
             */
            @JSONField(name = "color")
            private String color;

            /**
             * 年份
             */
            @JSONField(name = "year")
            private String year;

            /**
             * 价格
             */
            @JSONField(name = "purchasePrice")
            private String purchasePrice;

            /**
             * 尺寸
             */
            @JSONField(name = "size")
            private String size;

            /**
             * 款式
             */
            @JSONField(name = "style")
            private String style;

            /**
             * 商品类别ID
             */
            @JSONField(name = "categoryId")
            private String categoryId;

            /**
             * 必填，商品类别名称
             */
            @JSONField(name = "categoryName")
            private String categoryName;

            /**
             * 商品类别1
             */
            @JSONField(name = "categoryName1")
            private String categoryName1;

            /**
             * 商品类别2
             */
            @JSONField(name = "categoryName2")
            private String categoryName2;

            /**
             * 商品类型
             */
            @JSONField(name = "itemType")
            private String itemType;

            /**
             * 单位
             */
            @JSONField(name = "stockUnit")
            private String stockUnit;

            /**
             * 保质期天数
             */
            @JSONField(name = "shelfLife")
            private String shelfLife;

            /**
             * 默认包装代码
             */
            @JSONField(name = "packCode")
            private String packCode;

            /**
             * 多包装代码
             */
            @JSONField(name = "multiPackCodes")
            private String multiPackCodes;

            /**
             * 订单拆分单位
             */
            @JSONField(name = "splitUom")
            private String splitUom;

            /**
             * 图片URL
             */
            @JSONField(name = "imageUrl")
            private String imageUrl;

            /**
             * 创建时间
             */
            @JSONField(name = "createTime")
            private String createTime;

            /**
             * 更新时间
             */
            @JSONField(name = "updateTime")
            private String updateTime;
        }

        @NoArgsConstructor
        @Data
        public static class ExtendProps {
            /**
             * 自定义字段1
             */
            @JSONField(name = "key1")
            private String key1;

            /**
             * 自定义字段2，材质
             */
            @JSONField(name = "key2")
            private String key2;

            /**
             * 自定义字段3
             */
            @JSONField(name = "key3")
            private String key3;

            /**
             * 自定义字段4
             */
            @JSONField(name = "key4")
            private String key4;

            /**
             * 自定义字段5
             */
            @JSONField(name = "key5")
            private String key5;
        }
    }

}
